"""
http 请求和响应
"""
from socket import *

sock = socket()
sock.bind(("0.0.0.0",8888))
sock.listen(5)

#　等待浏览器连接
conn,addr = sock.accept()
print("Connect from",addr)

#　接收ｈｔｔｐ请求
data = conn.recv(1024)
print(data.decode())

# 组织http响应格式
response = """HTTP/1.1 200 OK
Content-Type:text/html

Hello World
"""
#　发送给浏览器
conn.send(response.encode())

conn.close()
sock.close()